package com.ocom.common.resp;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ocom.common.enums.ResultEnum;
import lombok.Data;

import java.io.Serializable;


//服务间响应类
@Data
@JsonIgnoreProperties(value = {"hibernateLazyInitializer"})
public class Result<T> implements Serializable {
    private static final Long serialVersionUID = -275582248840137389L;

    private Integer code;
    private String msg;
    @JsonIgnoreProperties(value = {"data", "data"})
    private T data;


    public Result(Integer result, String msg, T data) {
        this.code = result;
        this.msg = msg;
        this.data = data;
    }

    public Result(ResultEnum resultEnum) {
        this.code = resultEnum.getKey();
        this.msg = resultEnum.getMsg();
    }

    public Result(ResultEnum resultEnum, T data) {
        this.code = resultEnum.getKey();
        this.msg = resultEnum.getMsg();
        this.data = data;
    }

    public Result() {

    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "RespMachMessage{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
